/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package smartgrid;

import org.orm.PersistentException;
public class AnnotationProcessor {
	private int ID;
	
	private java.util.Date date;
	
	private String name;
	
	private String action="";
	
	public void setID(int value) {
		this.ID = value;
	}
	
	public int getID() {
		return ID;
	}
	
	public void setDate(java.util.Date value) {
		this.date = value;
	}
	
	public java.util.Date getDate() {
		return date;
	}
	
	public void setName(String value) {
		this.name = value;
	}
	
	public String getName() {
		return name == null ? "" : name;
	}
	
	public String getAction() {
		return action;
	}
	
	public void setAction(String action) {
		this.action = action;
	}
	
	private int contract_contractID;
	
	public void setContract_contractID(int value) {
		this.contract_contractID = value;
	}
	
	public int getContract_contractID() {
		return contract_contractID;
	}
	
	private int faceBookAccount_faceBookAccountID;
	
	public void setFaceBookAccount_faceBookAccountID(int value) {
		this.faceBookAccount_faceBookAccountID = value;
	}
	
	public int getFaceBookAccount_faceBookAccountID() {
		return faceBookAccount_faceBookAccountID;
	}
	
	public String process() {
		String result = "Unexcepted result";
		if (action.equals("search")) {
			smartgrid.Annotation _annotation = smartgrid.Annotation.loadAnnotationByORMID(getID());
			if (_annotation!= null) {
				copyFromBean(_annotation);
				result = "Search success";
			}
			else {
				result = "Search failed";
			}
		}
		else if(action.equals("insert"))  {
			try {
				smartgrid.Annotation _annotation = smartgrid.Annotation.createAnnotation();
				copyToBean(_annotation);
				if (_annotation.save()) {
					result = "Insert success";
				}
				else {
					result = "Insert failed";
				}
			}
			catch (Exception e) {
				result = "Insert error: " + e.toString();
			}
		}
		else if (action.equals("update")) {
			smartgrid.Annotation _annotation= smartgrid.Annotation.loadAnnotationByORMID(getID());
			if (_annotation != null) {
				copyToBean(_annotation);
				if (_annotation.save()) {
					result = "Update success";
				}
				 else {
					result = "Update failed";
				}
			}
			 else  {
				result = "Update failed";
			}
			
		}
		else if (action.equals("delete")) {
			smartgrid.Annotation _annotation = smartgrid.Annotation.loadAnnotationByORMID(getID());
			if (_annotation != null && _annotation.deleteAndDissociate()) {
				result = "Delete success";
			}
			else {
				result = "Delete failed";
			}
		}
		else if (action.equals("")) {
			result = "";
		}
		action = "";
		return result;
	}
	
	private void copyFromBean(smartgrid.Annotation _annotation) {
		setDate(_annotation.getDate());
		setName(_annotation.getName());
		setID(_annotation.getORMID());
		
		{
			smartgrid.Contract _contract = _annotation.getContract();
			if (_contract != null) {
				setContract_contractID(_contract.getORMID());
			}
		}
		
		
		{
			smartgrid.FaceBookAccount _faceBookAccount = _annotation.getFaceBookAccount();
			if (_faceBookAccount != null) {
				setFaceBookAccount_faceBookAccountID(_faceBookAccount.getORMID());
			}
		}
		
	}
	
	private void copyToBean(smartgrid.Annotation _annotation) {
		_annotation.setDate(getDate());
		_annotation.setName(getName());
		smartgrid.Contract _contract = smartgrid.Contract.loadContractByORMID(getContract_contractID());
		_annotation.setContract(_contract);
		smartgrid.FaceBookAccount _faceBookAccount = smartgrid.FaceBookAccount.loadFaceBookAccountByORMID(getFaceBookAccount_faceBookAccountID());
		_annotation.setFaceBookAccount(_faceBookAccount);
	}
	
}

